/*
 * testCommon.h
 *
 *  Created on: Sep 27, 2013
 * @author Daniel Rogers
 *
 */

#ifndef TEST_COMMON_H_
#define TEST_COMMON_H_

#include <stdbool.h>

/*
 * Checks if a test passed (result cubes are equal)
 *
 * @param base The cube known to be correct
 * @param working The cube to check
 * @param msg The message to print in the format: msg \n  -- Passed | Failed!
 *
 * @return false if the test failed
 */
bool assertTestPass(const Cube *base, const Cube *working, const char* msg)
{
    puts(msg);

    if (!equalCubes(base, working))
    {
        puts("  -- Failed!");

        uint8_t corners[8];
        uint8_t edges[12];

        puts("base state:");
        decodeCorners(base->corners, corners);
        decompressEdges(base->edges, edges);

        for (int i = 0; i < 8; ++i)
        {
            printf("    c[%d]: %d\n", i, corners[i]);
        }
        for (int i = 0; i < 12; ++i)
        {
            printf("    e[%d]: %d\n", i, edges[i]);
        }
        printf("    cspin: %x\n", base->corner_spin);
        printf("    espin: %x\n", base->edge_spin);

        puts("working state:");
        decodeCorners(working->corners, corners);
        decompressEdges(working->edges, edges);

        for (int i = 0; i < 8; ++i)
        {
            printf("    c[%d]: %d\n", i, corners[i]);
        }
        for (int i = 0; i < 12; ++i)
        {
            printf("    e[%d]: %d\n", i, edges[i]);
        }
        printf("    cspin: %x\n", working->corner_spin);
        printf("    espin: %x\n", working->edge_spin);

        return false;
    }
    else
    {
        puts("  -- Passed");
        return true;
    }
}

#endif

